package com.orphan.marketBack.service.impl;

import com.orphan.marketBack.dao.ReturnOrderMapper;
import com.orphan.marketBack.po.OrderReturn;
import com.orphan.marketBack.service.ReturnOrderService;
import com.orphan.util.dto.ReturnsDetailsDto;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service()
public class ReturnOrderServiceImpl implements ReturnOrderService {
    @Autowired
    RabbitTemplate rabbitTemplate;
    @Autowired
    ReturnOrderMapper returnOrderMapper;
    @Override
    public List<OrderReturn> selectAllReturn() {
        return returnOrderMapper.selectAllReturn();
    }

    @Override
    public List<OrderReturn> selectAllById(OrderReturn orderReturn) {
        return returnOrderMapper.selectAllById(orderReturn);
    }

    @Override
    public List<OrderReturn> selectOrder(OrderReturn orderReturn) {
        return null;
    }

    @RabbitListener(queues = "return")
    public void getOrderReturnMQ(ReturnsDetailsDto returnsDetailsDto){
        System.out.println(returnsDetailsDto);
        OrderReturn orderReturn = new OrderReturn();

        orderReturn.setOrderNo(returnsDetailsDto.getOrderId());
        orderReturn.setReturnsNo(returnsDetailsDto.getReturnsNo());
        orderReturn.setGoodsName(returnsDetailsDto.getGoodsName());
        orderReturn.setGoodsCount(returnsDetailsDto.getGoodsCount());
        orderReturn.setGoodsOrderStatus(returnsDetailsDto.getGoodsOrderStatus());
        orderReturn.setGoodsPrice(returnsDetailsDto.getGoodsPrice());
        orderReturn.setReturnsTime(returnsDetailsDto.getReturnsTime());
        orderReturn.setGoodsType(returnsDetailsDto.getGoodsType());

        int insert = returnOrderMapper.insert(orderReturn);
        if(insert > 0){
            rabbitTemplate.convertAndSend("queueOrderReturn","orderReturn",orderReturn);
        }

    }
}
